using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ClassifierLib.Classifier.Filters
{
    public class ExploreExploitSelect : RuleFilter
    {
        private ExploitSelect _exploit;
        private ExploreSelect _explore;
        private bool IsExploring = true;

        public ExploreExploitSelect()
        {
            _exploit = new ExploitSelect();
            _explore = new ExploreSelect();
            this.Name = "Explore Exploit Select";
            if (!RegisteredTypes.Contains(GetType()))
                RegisteredTypes.Add(GetType());   
        }
        public ExploreExploitSelect(ExploitSelect Exploit, ExploreSelect Explore)
        {
            _exploit = Exploit;
            _explore = Explore;

            this.Name = "Explore Exploit Select";
            if (!RegisteredTypes.Contains(GetType()))
                RegisteredTypes.Add(GetType()); 
        }

        /// <summary>
        /// Overriden to ensure that child rulefilter's recieve parent's value when set
        /// </summary>
        public override ActionFactory ActionFactory
        {
            get
            {
                return base.ActionFactory;
            }
            set
            {
                base.ActionFactory = value;
                _exploit.ActionFactory = value;
                _explore.ActionFactory = value;
            }
        }

        public override Population Apply(Population Population, Population Selected, Environment.State State, Action Action)
        {
            if (IsExploring)
            {
                IsExploring = false;
                return _explore.Apply(Population, Selected, State, Action);
            }
            else
            {
                IsExploring = true;
                return _exploit.Apply(Population, Selected, State, Action);
            }
        }

        [CategoryAttribute("Settings"), Browsable(true), ReadOnly(false), BindableAttribute(false), DesignOnly(false), DescriptionAttribute("The filter used during exploit phase")]
        public bool ExploreFirst
        {
            get
            {
                return IsExploring;
            }
            set
            {
                IsExploring = value;
                OnPropertyChanged("ExploreFirst");
            }
        }


        [CategoryAttribute("Filters"), Browsable(true), ReadOnly(true), BindableAttribute(false), DesignOnly(false), DescriptionAttribute("The filter used during exploit phase")]
        public ExploitSelect ExploitSelectFilter
        {
            get
            {
                return _exploit;
            }
        }

        [CategoryAttribute("Filters"), Browsable(true), ReadOnly(true), BindableAttribute(false), DesignOnly(false), DescriptionAttribute("The filter used during explore phase")]
        public ExploreSelect ExploreSelectFilter
        {
            get
            {
                return _explore;
            }
        }
    }
}
